const express = require('express')
const bodyParser = require('body-parser')
const app = express()
app.use(bodyParser.json())
//处理post请求
app.post('/', (req, res) => {
console.log('服务器获取前端数据成功!')
console.log(req.body)
})
//监听3000端口
app.listen(3000, () => {
console.log('server running at http://127.0.0.1:3000')
console.log('启动服务器成功!\n================')
})
//在服务器上添加用户数据
var userData=[
{userName:'李四',userGender:'男',userSkills:['C','Python','小程序'],userOpinion:'要学习的太多了！'},
{userName:'王五',userGender:'女',userSkills:['Linux','小程序'],userOpinion:'学习使人快乐！'}
]
//处理get请求
app.get('/',(req,res)=>{
res.json(userData)
console.log('服务器数据发送成功!')
})